/*
 * nume: client-to-client-thread-client.h
 * autor: ~D
 * descriere: thread-ul pe care il creaza un client pentru a comunica cu serverul
 * tabela de modificarei
 *   21 iun 2007 - ~D - prima versiune
 *   22 iun 2007 - ~D - threadul e functional
 */

#ifndef CLIENT_TO_SERVER_THREAD_CLIENT_H__
#define CLIENT_TO_SERVER_THREAD_CLIENT_H__

#include <QThread>
#include <QtCore>

#include "server-client-net.h"
#include "message.h"

class ServerClientThread : public QThread {
    Q_OBJECT

public:
    ServerClientThread(QObject *parent = 0);

    void run();
    void create_recv_socket(quint16 port);
    void send_message(quint32 address, quint16 port, Message* message);

    // obiectul devine proprietarul mesajului
    void enqueue_message(const Message* message, quint32 address);
    void head_message(const Message** message, quint32* address);
    void dequeue_message();

    quint32 queue_size();

signals:
    // void error(QTcpSocket::SocketError socketError);*/
    void message_received();

public slots:


private:
    ServerClientNet* net_;
    QList<const Message*> messages_list_;
    QList<quint32> addresses_list_;
    quint16 bind_port_;
    QMutex  mutex_;
};
 #endif
